const {
	Controller
} = require('uni-cloud-router')
const uniID = require('uni-id')

const dbHelper = require('db-helper')
module.exports = class UserController extends Controller {
	async addUser() {
		const {
			nickname,
			city,
			username,
			password,
			role,
			mobile,
			status,
			merchant_info,
			dcloudAppidList = []
		} = this.ctx.data
		
		let region = await dbHelper.getOne("t3ds-region", {
			'city.value': city
		})
		if (!region) {
			return {
				code: 500,
				msg: '不支持当前城市'
			}
		}
		try{
			let data = {
				nickname,
				city,
				username,
				password,
				role,
				mobile,
				status,
				merchant_info,
				dcloudAppidList
			}
			let res = await this.service.user.addUser(data)
			return {
				code: 200,
				result: res
			}
		}catch(e){
			return {
				code: 500,
				msg: e.message
			}
		}
	}
	
	async resetPwd() {
		const {
			uid,
			password
		} = this.ctx.data
	
		const result = await uniID.resetPwd({
			uid,
			password
		})

		return result
	}
}
